<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/public/header.jsp"%>
<%
	String purchase_id = request.getParameter("purchase_id") == null ? "" : request.getParameter("purchase_id");
%>
<html>
	<head>
		<title>打印预览</title>
		<style>
			.td1{
				padding-top:10px;
				padding-bottom:5px;
				font-size: 12px;
				background-color: #c0ebd7;
				width:20%;
			}
			.td2{
				padding:5px;
			}
		    .datagrid-cell {
			  font-size: 18px;
			}
		</style>
	<script type="text/javascript">
		$(function(){
				$('#ff').form('load','<%=contextPath %>/springMVC/warehouse/getPurchaseById?purchase_id=<%=purchase_id%>');
			$.ajax({
				type:'GET',
				url:'<%=contextPath %>/springMVC/warehouse/getPurchaseById?purchase_id=<%=purchase_id%>',
				success:function(rtData){
					$('#code').html(rtData.code);
					$('#contract_code').html(rtData.contract_code);
					$('#company').html(rtData.company);
					$('#admin').html(rtData.admin);
					$('#tel').html(rtData.tel);
					$('#fax').html(rtData.fax);
					$('#mail').html(rtData.mail);
					$('#operation_date').html(rtData.operation_date);
					$('#company1').html(rtData.company1);
					$('#admin1').html(rtData.admin1);
					$('#tel1').html(rtData.tel1);
					$('#fax1').html(rtData.fax1);
					$('#mail1').html(rtData.mail1);
					$('#gd_admin_name').html(rtData.gd_admin_name);
					$('#gd_name').html(rtData.gd_name);
					$('#gd_code').html(rtData.gd_code);
					$('#remark').html(rtData.remark);
				}
			});
			$('#table').datagrid({
				url:'<%=contextPath%>/springMVC/warehouse/listPurchaseDetail?purchase_id=<%=purchase_id%>',
				rownumbers:true,
				fitColumns:true,
				columns:[[
					{title:'产品编号',field:'code',width:150,align:'center'},
					{title:'产品名称',field:'name',width:300,align:'center'},
					{title:'规格/型号',field:'format_type',width:200,align:'center'},
					{title:'单位',field:'unit_name',width:100,align:'center'},
					{title:'单价',field:'cost',width:100,align:'center'},
					{title:'订货数量',field:'num',width:100,align:'center'},
					{title:'合计',field:'total',width:100,align:'center',formatter: function(value,row,index){
						if(row.cost == null || row.num == null || row.cost == '' || row.num == ''){
							return "";
						}
							return Math.round(parseFloat(row.num)*parseFloat(row.cost)*Math.pow(10,2))/Math.pow(10,2);
					}},
					{title:'备注',field:'remark',width:100,align:'center'}
				]],
				onLoadSuccess:function(rtJson){
					setTotalMsg();
				}
			});
			
		});
	function setTotalMsg(){
		var total_num = 0;
		var total_money = 0;
		var jsondata=$("#table").datagrid("getData");
		for(var i=0;i<jsondata.total;i++){
			var row = jsondata.rows[i];
			if(row.cost == null || row.num == null || row.cost == '' || row.num == ''){
				continue;
			}
			total_num += parseFloat(row.num);
			total_money += Math.round(parseFloat(row.num)*parseFloat(row.cost)*Math.pow(10,2))/Math.pow(10,2);
		}
		$('#total_num').html(total_num);
		$('#total_money').html(total_money);
	}
	function startPrint(obj){
		$(obj).hide();
		window.print();
	}
	</script>
	</head>
	<body>
		<div style="width: 90%;padding-left:50px">
		<form id="ff">
			<table  style="border-collapse: collapse;" width="100%" border="1px" bordercolor="#0eb83a">
				<tr>
					<td class="td2" align="center" colspan="7">
						<b><span  id="title">订货单</span></b>
					</td>
				</tr>
				<tr>
					<td align="right" class="td1" nowrap>订单编号：</td>
					<td class="td2" nowrap colspan='3'>
						<span id="code"></span>
					</td>
					<td align="right" class="td1" nowrap>合同编号：</td>
					<td class="td2" nowrap colspan='2'>
						<span id="contract_code"></span>
					</td>
				</tr>
				<tr>
					<td align="center" class="td1" nowrap rowspan='3'>甲<br>方</td>
					<td class="td2" nowrap colspan='6'>
						<span id="company"></span>
					</td>
				</tr>
				<tr>
					<td align="right" class="td1" nowrap>商务管理员：</td>
					<td class="td2" nowrap >
						<span id="admin"></span>
					</td>
					<td align="right" class="td1" nowrap>TEL：</td>
					<td class="td2" nowrap >
						<span id="tel"></span>
					</td>
					<td align="right" class="td1" nowrap>FAX：</td>
					<td class="td2" nowrap >
						<span id="fax"></span>
					</td>
				</tr>
				<tr>
					<td align="right" class="td1" nowrap>MAIL：</td>
					<td class="td2" nowrap colspan='3'>
						<span id="mail"></span>
					</td>
					<td align="right" class="td1" nowrap>订单日期：</td>
					<td class="td2" nowrap >
						<span id="operation_date"></span>
					</td>
				</tr>
				<tr>
					<td align="center" class="td1" nowrap rowspan='3'>乙<br>方</td>
					<td class="td2" nowrap colspan='6'>
						<span id="company1"></span>
					</td>
				</tr>
				<tr>
					<td align="right" class="td1" nowrap>联系人：</td>
					<td class="td2" nowrap >
						<span id="admin1"></span>
					</td>
					<td align="right" class="td1" nowrap>TEL：</td>
					<td class="td2" nowrap >
						<span id="tel1"></span>
					</td>
					<td align="right" class="td1" nowrap>FAX：</td>
					<td class="td2" nowrap >
						<span id="fax1"></span>
					</td>
				</tr>
				<tr>
					<td align="right" class="td1" nowrap>MAIL：</td>
					<td class="td2" nowrap colspan='5'>
						<span id="mail1"></span>
					</td>
				</tr>
				<tr>
					<td align="center" class="td1" nowrap rowspan='4'>订<br>货<br>单<br>信<br>息</td>
				</tr>
				<tr>
					<td align="right" class="td1" nowrap>工单管理员：</td>
					<td class="td2" nowrap colspan='5'>
						<span id="gd_admin_name"></span>
					</td>
				</tr>
				<tr>
					<td align="right" class="td1" nowrap>工单名称：</td>
					<td class="td2" nowrap colspan='5'>
						<span id="gd_name"></span>
					</td>
				</tr>
				<tr>
					<td align="right" class="td1" nowrap>工单编号：</td>
					<td class="td2" nowrap colspan='5'>
						<span id="gd_code"></span>
					</td>
				</tr>
				<tr>
					<td align="right" class="td1" nowrap>摘要：</td>
					<td class="td2" nowrap colspan='6'>
						<span id="remark"></span>
					</td>
				</tr>
				<tr>
					<td align="right" class="td1" nowrap></td>
					<td class="td2" nowrap colspan='7'>
						<div align="left">
							<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-print'" onclick="startPrint(this);">确认打印</a>
						</div>
					</td>
				</tr>				<tr>
					<td colspan="7"  nowrap>
						<div id="table"></div>
					</td>
				</tr>
				<tr>
					<td colspan='7' nowrap>
						<div style="padding:3px" align="right">
							合计数量：<span id='total_num' style="color: red">0</span>
							合计金额：￥<span id='total_money' style="color: red">0</span>
						</div>
					</td>
				</tr>
			</table>
			</form>
		</div>
	</body>
</html>